Passed
Push — develop ( b6a64d...7bef1a )
by Andrew
04:05
created

webpack.dev.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
// webpack.dev.js - developmental builds
2
const LEGACY_CONFIG = 'legacy';
3
const MODERN_CONFIG = 'modern';
4
5
// node modules
6
const merge = require('webpack-merge');
7
const path = require('path');
8
const sane = require('sane');
9
const webpack = require('webpack');
10
11
// webpack plugins
12
13
// config files
14
const pkg = require('./package.json');
15
const common = require('./webpack.common.js');
16
17
// Configure the webpack-dev-server
18
const configureDevServer = (buildType) => {
0 ignored issues
show
Unused Code introduced by
The parameter buildType is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
19
    return {
20
        public: pkg.project.devServerConfig.public,
21
        contentBase: path.resolve(__dirname, pkg.project.paths.templates),
22
        host: pkg.project.devServerConfig.host,
23
        hot: true,
24
        hotOnly: true,
25
        overlay: true,
26
        stats: 'errors-only',
27
        watchOptions: {
28
            poll: pkg.project.devServerConfig.poll
29
        },
30
        headers: {
31
            'Access-Control-Allow-Origin': '*'
32
        },
33
        // Use sane to monitor all of the templates files and sub-directories
34
        before: (app, server) => {
35
            const watcher = sane(path.join(__dirname, pkg.project.paths.templates), {
36
                glob: ['**/*'],
37
                poll: pkg.project.devServerConfig.poll,
38
            });
39
            watcher.on('change', function (filePath, root, stat) {
0 ignored issues
show
Unused Code introduced by
The parameter stat is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter root is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
40
                console.log('  File modified:', filePath);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
41
                server.sockWrite(server.sockets, "content-changed");
42
            });
43
        },
44
    };
45
};
46
47
// Configure the Postcss loader
48
const configurePostcssLoader = (buildType) => {
49
    // Don't generate CSS for the legacy config in development
50
    if (buildType === LEGACY_CONFIG) {
51
        return {
52
            test: /\.(pcss|css)$/,
53
            loader: 'ignore-loader'
54
        };
55
    }
56
    if (buildType === MODERN_CONFIG) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if buildType === MODERN_CONFIG is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
57
        return {
58
            test: /\.(pcss|css)$/,
59
            use: [
60
                {
61
                    loader: 'style-loader',
62
                },
63
                {
64
                    loader: 'css-loader',
65
                    options: {
66
                        importLoaders: 2,
67
                        sourceMap: true
68
                    }
69
                },
70
                {
71
                    loader: 'resolve-url-loader'
72
                },
73
                {
74
                    loader: 'postcss-loader',
75
                    options: {
76
                        sourceMap: true
77
                    }
78
                }
79
            ]
80
        };
81
    }
82
};
83
84
// Development module exports
85
module.exports = [
86
    merge(
87
        common.legacyConfig,
88
        {
89
            output: {
90
                filename: path.join('./js', '[name]-legacy.[hash].js'),
91
                publicPath: pkg.project.devServerConfig.public + '/',
92
            },
93
            mode: 'development',
94
            devtool: 'inline-source-map',
95
            devServer: configureDevServer(LEGACY_CONFIG),
96
            module: {
97
                rules: [
98
                    configurePostcssLoader(LEGACY_CONFIG),
99
                ],
100
            },
101
            plugins: [
102
                new webpack.HotModuleReplacementPlugin()
103
            ],
104
        }
105
    ),
106
    merge(
107
        common.modernConfig,
108
        {
109
            output: {
110
                filename: path.join('./js', '[name].[hash].js'),
111
                publicPath: pkg.project.devServerConfig.public + '/',
112
            },
113
            mode: 'development',
114
            devtool: 'inline-source-map',
115
            devServer: configureDevServer(MODERN_CONFIG),
116
            module: {
117
                rules: [
118
                    configurePostcssLoader(MODERN_CONFIG),
119
                ],
120
            },
121
            plugins: [
122
                new webpack.HotModuleReplacementPlugin()
123
            ],
124
        }
125
    ),
126
];
127